package org.iamd.hibernate.vo;

import static javax.persistence.FetchType.LAZY;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

/**
 * Номенклатура, която представлява менюто на системата.
 * 
 * @author И. Атанасов
 */
@Entity
@Table(name = "nom_menus", uniqueConstraints = @UniqueConstraint(columnNames = "system_name"))
public class NomMenu extends TreeNomElemVO {

	/** Сериен номер на класа. */
	private static final long serialVersionUID = -3791939651720968100L;

	/** Изход след избиране на менюто. */
	private String outcome;

	/**
	 * @see NomElemVO#getDescription()
	 */
	@Override
	@Column(name = "description")
	public String getDescription() {
		return super.getDescription();
	}

	/**
	 * @see HibernateVO#getId()
	 */
	@Override
	@Id
	@Column(name = "id", unique = true, nullable = false)
	public Integer getId() {
		return super.getId();
	}

	/**
	 * @see NomElemVO#getName()
	 */
	@Override
	@Column(name = "name", nullable = false, length = 100)
	public String getName() {
		return super.getName();
	}

	/**
	 * @return родителското меню
	 */
	@ManyToOne(fetch = LAZY)
	@JoinColumn(name = "p_id")
	public NomMenu getNomMenu() {
		return (NomMenu) super.getParent();
	}

	/**
	 * @return подменютата
	 */
	@SuppressWarnings("unchecked")
	@OneToMany(fetch = LAZY, mappedBy = "nomMenu")
	public List<NomMenu> getNomMenus() {
		return (List<NomMenu>) super.getChildren();
	}

	/**
	 * @see NomElemVO#getOrdering()
	 */
	@Override
	@Column(name = "ordering", nullable = false)
	public Integer getOrdering() {
		return super.getOrdering();
	}

	/**
	 * @return Навигацията
	 */
	@Column(name = "outcome", length = 50)
	public String getOutcome() {
		return this.outcome;
	}

	/**
	 * @see NomElemVO#getSystemName()
	 */
	@Override
	@Column(name = "system_name", unique = true, nullable = false, length = 50)
	public String getSystemName() {
		return super.getSystemName();
	}

	/**
	 * @param nomMenu
	 *            родителското меню
	 * 
	 * @see TreeNomElemVO#setParent(TreeNomElemVO)
	 */
	public void setNomMenu(NomMenu nomMenu) {
		super.setParent(nomMenu);
	}

	/**
	 * @param nomMenus
	 *            подменютата
	 * 
	 * @see TreeNomElemVO#setChildren(List)
	 */
	public void setNomMenus(List<NomMenu> nomMenus) {
		super.setChildren(nomMenus);
	}

	/**
	 * Setter за навигацията.
	 * 
	 * @param outcome
	 *            навигация
	 */
	public void setOutcome(String outcome) {
		this.outcome = outcome;
	}

}